home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / HeartQuest sample ƒ / sBonus.p < prev    next >
Encoding:
Text File  |  1994-07-26  |  1.8 KB  |  80 lines  |  [TEXT/PJMM]

  1. {===============================================}
  2. {================= Bonus sprite unit ================}
  3. {===============================================}
  4.  
  5. { Example file for Ingemars Sprite Animation Toolkit. }
  6. { © Ingemar Ragnemalm 1992 }
  7. { See doc files for legal terms for using this code. }
  8.  
  9. unit sBonus;
  10.  
  11. { Sprite unit. A sprite unit should include the following routines:}
  12. { Init-procedure, that initializes private bitmaps}
  13. { Setup-procedure, that sets variables other than the standard ones set by MakeSprite }
  14. { Handle-procedure, to be called once per iteration until the sprite dies }
  15. { Hittask-procedure (optional), for advanced collission handling. }
  16.  
  17. interface
  18.  
  19.     uses
  20.         SAT, sPoints, scores, SoundConst, GameGlobals;
  21.  
  22.     procedure InitBonus;
  23.     procedure SetupBonus (mp: SpritePtr);
  24.     procedure HandleBonus (me: SpritePtr);
  25.  
  26. implementation
  27.  
  28.     var
  29.         BonusFace: array[1..3] of FacePtr;
  30.  
  31.     procedure InitBonus;
  32.         var
  33.             ii: integer;
  34.             h: handle;
  35.     begin
  36.         for ii := 1 to 3 do
  37.             begin
  38.                 BonusFace[ii] := GetFace(127 + ii);
  39.             end;
  40.     end;
  41.  
  42.     procedure SetupBonus (mp: SpritePtr);
  43.         var
  44.             i: integer;
  45.     begin
  46.         i := rand(3) + 1;
  47.         mp^.face := BonusFace[i];
  48. {mp^.mask := Bonusmask[i];}
  49.  
  50.         if mp^.position.h < 300 then
  51.             mp^.speed.h := 5
  52.         else
  53.             mp^.speed.h := -5;
  54.         SetRect(mp^.hotRect, -13 + 16, -28 + 32, 13 + 16, 0 + 32);
  55.  
  56.         mp^.task := @HandleBonus;
  57.     end;
  58.  
  59.     procedure HandleBonus (me: SpritePtr);
  60.         var
  61.             mp: Spriteptr;
  62.     begin
  63.         if me^.kind <> -4 then
  64.             begin
  65.                 me^.task := nil; { Caught by the player! }
  66.                 addscore(50);
  67.                 mp := NewSprite(0, me^.position.h, me^.position.v, @SetupPoints);
  68.                 SATSoundPlay(jaSndH, 5, true);
  69.             end;
  70.  
  71.         me^.mode := me^.mode + 1;
  72.  
  73.         me^.position.h := me^.position.h + me^.speed.h;
  74.         if me^.position.h > gSAT.offSizeH then
  75.             me^.task := nil;
  76.         if me^.position.h < -32 then
  77.             me^.task := nil;
  78.     end;
  79.  
  80. end.